import * as PIXI from 'pixi.js'
import { categoryModule } from '@/utils/bundle'
import { CATEGORY } from '@/config'
import useDiyStore from '@/store/modules/useDiyStore'
import { getPixiData, setPixi } from '@/store/modules/usePixiStore'
import param from '../param'
export default async () => {
  const diyStore = useDiyStore()
  const container = new PIXI.Container()
  await Promise.all(
    Object.entries(CATEGORY).map(async ([typeKey, categorys]) => {
      await Promise.all(
        Object.entries(categorys).map(async ([key]) => {
          const categoryContainerData = getPixiData(param.value.categoryKey[key]) // 类型数据
          const sprite = await categoryModule({
            type: typeKey,
            category: key,
          } as Wx.Card.Param)
          sprite.anchor.set(0.5)
          sprite.scale.set(0.5)
          sprite.position.set(0, 506 / 2 - 20)
          sprite.visible = diyStore.creationData.category === key
          categoryContainerData.rightCategory = sprite.uid // 将类别与右侧关联
          setPixi(sprite.uid, sprite)
          container.addChild(sprite)
        }),
      )
    }),
  )
  return container
}
